﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "Shenqingdan";
}
<h3>@Resource.String33</h3>
<from class="from-horizontal">
    <div>
        <fieldset class="boun nav" style="padding-bottom:6px;">
            <legend class="len">@Resource.String402</legend>
            <div class="col-lg-3">@Resource.String400:<input type="text" style="width:150px;" id="txtbian" /></div>
            <div class="col-lg-3">@Resource.String401:<input type="text" style="width: 150px;" id="txtKH" /></div>
            <div class="col-lg-3">@Resource.String402:<input type="text" style="width: 150px;" id="txtqishi" /></div>
            <div calss="col-lg-3"><button id="findApp" class="btn-sm btn-secondary">@Resource.String403</button>&nbsp;&nbsp;<button id="reste" class="btn-sm btn-secondary">  @Html.ActionLink("回到首页", "Zuye", new { Controller = "Home", Action = "Zuye" }, new { @style = "color:#fff" })</button></div>
        </fieldset>
    </div>
    <div class="tab">
        <fieldset class="boun nav">
            <legend class="len">@Resource.String404</legend>
            <table class="table table-sm gun" border="1">
                <thead class="thead-light">
                    <tr style="text-align:center">
                        <th scope="col">@Resource.String405</th>
                        <th scope="col">@Resource.String406</th>
                        <th scope="col">@Resource.String407</th>
                        <th scope="col">@Resource.String408</th>
                        <th scope="col">单据状态</th>
                        <th scope="col">源单</th>
                    </tr>
                </thead>
                <tbody id="AppTable" style="height:500px;">
                    @foreach (var item in ViewBag.shunf as List<JiCheng>)
                    {
                        <tr>
                            <td id="CG_ZT">@item.JC_bianma</td>
                            <td>@item.JC_bianhao</td>
                            <td>@item.JC_shen</td>
                            <td>@item.JC_shi</td>
                            <td id="JC_tijaio" style="color: blue">
                                @if (item.JC_ung == "重新审核中")
                                {

                                    @item.JC_ung
                                }
                                else
                                {
                                    @item.JC_zhuang

                                }
                            </td>
                            <td>@item.JC_Yuan</td>
                        </tr>
                    }
                </tbody>
            </table>
        </fieldset>
    </div>
</from>

@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li10").css({ "color": "black", "background-color": "white" })
            Application_form_information()
            Preview_the_quotation()
            //打印申请表信息
            function Application_form_information() {
                $("#findApp").click(function () {
                    var txtbian = $("#txtbian").val();
                    var txtKH = $("#txtKH").val();
                    var txtqishi = $("#txtqishi").val();
                    $.ajax({
                        url: '/Home/sjdnww',
                        type: 'GET',
                        data: { "App_bian": txtbian, "App_KHname": txtKH, "App_xiang": txtqishi, "state": 1 },
                        success: function (data) {
                            console.log(data)
                            createRow(data);
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })

                })
            }
            function createRow(data) {
                $('#AppTable tr').remove();
                $.each(data, function (i, item) {
                    var $tr = $(`<tr>
                                                <td id="CG_ZT">${item.JC_bianma}</td>
                                                <td>${item.JC_bianhao}</td>
                                                <td>${item.JC_shen}</td>
                                                <td>${item.JC_shi}</td>
                                                <td id="JC_tijaio" style="color:blue">${item.JC_zhuang}</td>
                                            </tr>`);
                    $('#AppTable').append($tr);
                })
            }
            function Preview_the_quotation() {
                $(document).on("click", "#CG_CK", function (e) {
                    var HJ_CP_sqd = $(e.target).prev().prev().prev().prev().prev().text()
                    console.log(HJ_CP_sqd)
                    window.location.href = "/Home/About?App_bian=" + HJ_CP_sqd;
                })
            }
            function Preview_the_quotation() {
                $(document).on("click", "#CG_SP", function (e) {
                    var HJ_CP_sqd = $(e.target).prev().prev().prev().prev().prev().prev().text()
                    window.location.href = "/Detailed/BomsView?names=" + HJ_CP_sqd;
                })
            }
            $(document).on("click", "#JC_tijaio", function (e) {
                var JC_jsn = $(e.target).text()
                var sjifn = $(e.target).prev().prev().prev().text()
                var sjifned = $(e.target).prev().prev().prev().prev().text()
                let zzde = /[\u4e00-\u9fa5]+/
                var shnfn = JC_jsn.match(zzde)
                console.log(shnfn)
                if (shnfn == "审核中") {
                    alert("正在审批，请等待");
                } else if (shnfn == "重新审核") {
                    $.ajax({
                        url: '/Home/sjdnww',
                        type: 'GET',
                        data: { "App_bian": sjifn, "state": 2, "jsokk": sjifned },
                        success: function (data) {
                            console.log(data);
                            alert(data);
                            window.location.href = "/Procure/Overview";;
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                } else {
                    $.ajax({
                        url: '/Home/sjdnww',
                        type: 'GET',
                        data: { "App_bian": sjifn, "state": 3 },
                        success: function (B_dount) {
                            console.log(B_dount)
                            if (B_dount == 1) {
                                alert("请重新创建！");
                            } else if (B_dount == 2) {
                                window.location.href = "/Detailed/Boms?names=" + sjifn;
                            } else if (B_dount == 3) {
                                window.location.href = "/Material/Index?names=" + sjifn;
                            } else if (B_dount == 4 || B_dount == 5) {
                                window.location.href = "/Procure/Overview";
                            } else if (B_dount == 6) {
                                window.location.href = "/Home/Quotation_to_be_generated";
                            }
                        },
                        error: function () {
                            alert("错误 请重试！")
                        }
                    })
                }
            })
        })
    </script>
}